package com.kyle.silverbullet.admin.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;

/**
 * <p>
 * 管理员表 RestApi
 * </p>
 *
 * @author kyle
 * @since 2020年8月8日
 */
@Profile("prod")
@EnableWebFluxSecurity
public class SecurityConfig {
    @Bean
    @ConditionalOnWebApplication(
            type = ConditionalOnWebApplication.Type.REACTIVE
    )
    public SecurityWebFilterChain configure(ServerHttpSecurity http) throws Exception {
        return http
                .authorizeExchange(config -> {
                    config.anyExchange().permitAll();
                })
                .formLogin(ServerHttpSecurity.FormLoginSpec::disable)
                .oauth2Login(Customizer.withDefaults())
                .build();
    }
}